package com.cjst.service.impl.base;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.cjst.pojo.base.ShortTemplate;
import com.cjst.service.base.ShortTemplateService;
import com.cjst.util.SendSmsUtil;

@Service
public class ShortTemplateServiceImpl extends BaseServiceImpl<ShortTemplate, String> implements ShortTemplateService{
	@Autowired
	private SendSmsUtil sendSmsUtil;
	/**
	 * 更新阿里平台模板到自己服务器
	 * @return
	 */
	@Override
	public int sx(){
		List<ShortTemplate> stList=this.list(null);
		if(stList!=null && stList.size()>0){
			for (ShortTemplate shortTemplate : stList) {
				String jsonStr=sendSmsUtil.querySmsTemplate(shortTemplate.getTemplateCode());
				JSONObject rowData = JSONObject.parseObject(jsonStr);
				String templateStatusStr=rowData.getString("TemplateStatus");
				if(templateStatusStr!=null && templateStatusStr.length()>0){
					shortTemplate.setTemplateStatus(Integer.parseInt(templateStatusStr));
				}
				String templateTypeStr=rowData.getString("TemplateType");
				if(templateTypeStr!=null && templateTypeStr.length()>0){
					shortTemplate.setTemplateType(Integer.parseInt(templateTypeStr));
				}
				String templateName=rowData.getString("TemplateName");
				shortTemplate.setTemplateName(templateName);
				String templateContent=rowData.getString("TemplateContent");
				shortTemplate.setTemplateContent(templateContent);
				this.updateLocal(shortTemplate);
			}
		}
		return 1;
	}
}
